const router = require ("koa-router")();
const usersModel = require("../../models/user");
router.post("/m1/doLogin",async ctx=>{
    var {username,password} = ctx.request.body;
    var data = await usersModel.find({username,password});
    if(data[0]){
        ctx.cookies.set("login",true);
        ctx.redirect("/");
        console.log("登录成功");
    }else{
        console.log("用户名或者密码错误！");
        ctx.body = (`<script>alert("登陆失败用户名或密码错误");location.href="/login"</script>`)
        // ctx.redirect("/login");
    }
})

module.exports = router;